//
//  UIBarButtonItem+Extention.swift
//  MYSinaWeico
//
//  Created by Magic Yu on 16/4/8.
//  Copyright © 2016年 Magic Yu. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    //构造函数
    convenience init(imgName: String? = nil,title: String? = nil,target: AnyObject?,action: Selector) {
        self.init()
        
        //设置按钮
        let btn = UIButton()
        //给按钮添加点击事件
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        //设置图片
        if let img = imgName{
        btn.setImage(UIImage(named: img), forState: .Normal)
        btn.setImage(UIImage(named:img + "_highlighted"), forState: .Highlighted)
        }
        //设置文字大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.setTitle(title, forState: .Normal)
        //设置颜色
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        //设置大小和内容发小一致
        btn.sizeToFit()
        //设置自定义视图
        customView = btn
    }
}